package com.bhkj.pdjhbgnewproject.core.service;

import android.widget.Toolbar;

import com.bhkj.pdjhbgnewproject.R;
import com.bhkj.pdjhbgnewproject.common.bean.PersonInfoBean;
import com.bhkj.pdjhbgnewproject.common.callback.CallbackManager;
import com.bhkj.pdjhbgnewproject.common.callback.IGlabolCallback;
import com.bhkj.pdjhbgnewproject.common.contanct.Contacts;
import com.bhkj.pdjhbgnewproject.common.utils.Tools;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

public class PdInfoSchduledExcutor implements Runnable {
    PersonInfoBean personInfoBean;

    public PdInfoSchduledExcutor(PersonInfoBean personInfoBean) {
        this.personInfoBean = personInfoBean;
    }


    @Override
    public void run() {
        obtainPdInfoFromNetLogic();
    }

    /**
     * 判断如果绑定activity或者窗口activity出现
     * 关闭BindActivity或者NotLoginActivity，同时打开MainActivity
     */
//    private void judgeBindOrWindowActivityExits() {
//
//    }

    /**
     * 实现具体的访问接口获取排队信息的逻辑
     */
    private void obtainPdInfoFromNetLogic() {
        LogUtils.d("获取排队信息");
        String id = personInfoBean == null ? "-1" : personInfoBean.getDatas().getID();
        String deptId = personInfoBean==null?"-1":personInfoBean.getDatas().getDEPTID();
        EasyHttp.get("queue/getQueue")
                .params("wid", Tools.encrypt(id))
                .params("deptid",Tools.encrypt(deptId))
                .params("size", Tools.encrypt("6"))
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        ToastUtils.showShort(StringUtils.getString(R.string.tip_connect_error) + "-" + e.getCode());
                    }

                    @Override
                    public void onSuccess(String s) {
                        LogUtils.i(s);
                        IGlabolCallback callback = CallbackManager.getInstance().getCallback(Contacts.FRESH_PD_INFO);
                        if (callback != null) {
                            callback.executeCallback(s);
                        }

                    }
                });
    }
}
